import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:lib_bitcoin_base/bitcoin_base.dart';
import 'package:lib_database/lib_database.dart';
import 'package:lib_util/lib_util.dart';

import '../../../../module_common/provider/wallet_info_provider.dart';
import '../../../../module_common/widgets/button/public_button.dart';
import '../../../../module_common/widgets/dialog/bottom_sheet_widget.dart';
import '../../../../module_common/widgets/public_tip/public_tip.dart';

//导出私钥弹窗
class ExportPrivateKeySheet extends StatefulWidget {
  const ExportPrivateKeySheet({Key? key}) : super(key: key);

  @override
  _ExportPrivateKeySheetState createState() => _ExportPrivateKeySheetState();
}

class _ExportPrivateKeySheetState extends State<ExportPrivateKeySheet> {
  @override
  Widget build(BuildContext context) {
    return BottomSheetWidget(
      title: '',
      expand: false,
      child: Container(
        padding: EdgeInsets.only(left: 20.w, right: 20.w),
        child: Column(
          children: [
            Row(
              children: [
                Image.asset(
                  'assets/images/status/warn.png',
                  width: 20.w,
                  height: 20.w,
                ),
                SizedBox(width: 7.w),
                Text("Export Private Key",
                    style: TextStyle(fontSize: 16.sp, fontWeight: FontWeight.bold, color: "#333333".toColor()))
              ],
            ),
            SizedBox(height: 5.w),
            Text(
              'Please write down the private key correctly and store it securely.Avoid online storage to prevent leaks',
              style: TextStyle(fontSize: 12.sp, color: "#868391".toColor()),
            ),
            SizedBox(height: 15.w),
            Container(
              decoration: BoxDecoration(borderRadius: BorderRadius.circular(10.w), color: '#F6F6F6'.toColor()),
              padding: EdgeInsets.all(15.w),
              child: InkWell(
                child: Text(
                  _showPrivateKey(),
                  style: TextStyle(color: '#333333'.toColor(), fontSize: 14.sp),
                ),
                onLongPress: () {
                  Clipboard.setData(ClipboardData(text: _showPrivateKey()));
                  Toast.show(context, message: 'Copy successfully');
                },
              ),
            ),
            SizedBox(height: 15.w),
            PublicButton(
              text: 'Back',
              margin: EdgeInsets.zero,
              onClick: () {
                Navigator.of(context).pop();
                Navigator.of(context).pop();
              },
            ),
            SizedBox(height: (MediaQuery.of(context).padding.bottom + 11).w)
          ],
        ),
      ),
    );
  }

  String _showPrivateKey() {
    var walletInfo = context.read<WalletInfoNotifier>().walletInfo;
    if (null == walletInfo) {
      return '';
    } else {
      return ObjectBox().getKeyByWalletInfo(walletInfo) ?? '';
    }
  }
}
